<?php

/**
 * country actions.
 *
 * @package    erp-crm
 * @subpackage country
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class countryActions extends sfActions
{
  public function executeIndex(){
    $this->listCountriesForm = new ListCountriesForm();
    $this->listCountriesList = ListCountriesPeer::doSelectSortByName();
  }

  
  public function executeInsert($request){
    $this->listCountriesForm = new ListCountriesForm();
    $list_countries = $request->getParameter('list_countries');
    $list_countries['iden'] = myStringGenerator::getIden();
    $this->listCountriesForm->bind($list_countries);
    if($this->listCountriesForm->isValid()){
      $this->listCountriesForm->save();
      $this->redirect('country/index');
    }else{
      $this->listCountriesList = ListCountriesPeer::doSelectSortByName();
      $this->setTemplate('index');
    }
  }
  
  public function executeEdit($request){
    $this->listCountriesForm = new ListCountriesForm(ListCountriesPeer::retrieveByPk($request->getParameter('iden')));
    $this->forward404Unless($this->listCountriesForm);
    $this->listCountriesList = ListCountriesPeer::doSelectSortByName();
    $this->setTemplate('index');
  }
  
  public function executeUpdate($request){
    $list_countries_params = $request->getParameter('list_countries');
    $listCountries = ListCountriesPeer::retrieveByPk($list_countries_params['iden']);
    $this->forward404Unless($listCountries);
    $this->listCountriesForm = new ListCountriesForm($listCountries);
    $this->listCountriesForm->bind($list_countries_params);
    if($this->listCountriesForm->isValid()){
      $this->listCountriesForm->save();
      $this->redirect('country/index');
    }else{
      $this->listCountriesList = ListCountriesPeer::doSelectSortByName();
      $this->setTemplate('index');
    }
  }
  
  public function executeDelete(){
    $listCountries = ListCountriesPeer::retrieveByPk($this->getRequestParameter('iden'));
    $this->forward404Unless($listCountries);
    $listCountries->delete();
    $this->redirect('country/index');
  }
  
}
